package com.yt.generator.engine.config;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Service模板生成的配置
 *
 * @author fengshuonan
 * @date 2017-05-07 22:12
 */
@Data
public class ServiceConfig {

    private ContextConfig contextConfig;

    private String pathTemplate;
    private String packageName; //service包名

    private List<String> imports;

    public void init() {
        ArrayList<String> imports = new ArrayList<>();
        imports.add("com.baomidou.mybatisplus.service.IService");

        if (StringUtils.isNotEmpty(contextConfig.getModuleName())){
            imports.add(contextConfig.getProjectBasePackageName() + ".models.bo." + contextConfig.getModuleName() + "." + contextConfig.getEntityName() + "SaveBO");
            imports.add(contextConfig.getProjectBasePackageName() + ".models.dto." + contextConfig.getModuleName() + "." + contextConfig.getEntityName() + "DTO");
        } else {
            imports.add(contextConfig.getProjectBasePackageName() + ".models.bo." + contextConfig.getEntityName() + "SaveBO");
            imports.add(contextConfig.getProjectBasePackageName() + ".models.dto." + contextConfig.getEntityName() + "DTO");
        }


        this.imports = imports;

        if (StringUtils.isNotEmpty(contextConfig.getModuleName())) {
            this.packageName = contextConfig.getProjectBasePackageName() + ".models.service." + contextConfig.getModuleName();
        } else {
            this.packageName = contextConfig.getProjectBasePackageName() + ".models.service";
        }

        //service模板生成路径
        if (StringUtils.isNotEmpty(contextConfig.getModuleName())) {
            this.pathTemplate = "\\" + contextConfig.getProjectName() + "-models\\src\\main\\java\\" + contextConfig.getProjectBasePackageName().replaceAll("\\.", "\\\\") + "\\models\\service\\" + contextConfig.getModuleName() + "\\I{}Service.java";
        } else {
            this.pathTemplate = "\\" + contextConfig.getProjectName() + "-models\\src\\main\\java\\" + contextConfig.getProjectBasePackageName().replaceAll("\\.", "\\\\") + "\\models\\service\\I{}Service.java";
        }

    }
}
